package cn.java79.quiz.web;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author oldliu
 * @since 1.0
 */
@WebFilter(filterName = "time",value = "/*")
public class TimeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("进入了TimeFilter");
        long start=System.nanoTime();
        HttpServletRequest request= (HttpServletRequest) servletRequest;
        String path=request.getServletPath();
        //放行！
        filterChain.doFilter(request,servletResponse);
        long end=System.nanoTime();
        System.out.println("访问 "+path+" 耗时"+(end-start)+"纳秒");
    }

    @Override
    public void destroy() {

    }
}
